/// @tags:
#include <cstdio>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1e5 + 5, BIT = 18;

struct Edge {
  int v, nxt;
} e[N << 1];

int f[18][N << 1], dep[N << 1], dfn[N], lg[N << 1], cnt;
int ans, heads[N], e_cnt;
int u[N], v[N], lca[N], nxt[N << 1], begin[N], head[N], fa[N << 1], rev[N << 1];

inline void add(int u, int v) {
  e[++e_cnt].nxt = heads[u], e[e_cnt].v = v, heads[u] = e_cnt;
  e[++e_cnt].nxt = heads[v], e[e_cnt].v = u, heads[v] = e_cnt;
}

inline int min(int a, int b) { return dep[a] < dep[b] ? a : b; }

void dfs1(int u, int fa) {
  f[0][++cnt] = u;
  dfn[u] = cnt;
  for (int i = heads[u], v; i; i = e[i].nxt)
    if ((v = e[i].v) != fa) dep[v] = dep[u] + 1, dfs1(v, u), f[0][++cnt] = u;
}

inline int getLCA(int a, int b) {
  a = dfn[a], b = dfn[b];
  if (a > b) std::swap(a, b);
  int k = lg[b - a + 1];
  return min(f[k][a], f[k][b - (1 << k) + 1]);
}

int find(int a) {
  if (fa[fa[a]] == fa[a]) return fa[a];
  else {
    int b = find(fa[a]);
    rev[a] ^= rev[fa[a]];
    return fa[a] = b;
  }
}

inline void merge(int a, int b, int c) {
  if (find(a) != find(b)) {
    c ^= rev[a] ^ rev[b];
    rev[fa[b]] = c;
    fa[fa[b]] = fa[a];
  }
}

int dfs(int u, int fa) {
  int mindep = 0x3f3f3f3f;  //最多能覆盖的两条路径深度
  for (int i = heads[u], v; i; i = e[i].nxt)
    if ((v = e[i].v) != fa) {
      mindep = std::min(mindep, dfs(v, u));
      if (head[u]) nxt[head[u]] = begin[v];
      else
        begin[u] = begin[v];
      if (head[v]) head[u] = head[v];
    }
  if (mindep < dep[u]) {
    ans += 2;
    return mindep;
  }
  while (begin[u] && dep[lca[begin[u] / 2]] >= dep[u])
    begin[u] = nxt[begin[u]];  //删除lca低于u的路径
  int x = begin[u];
  if (x) {
    ans++;
    while (nxt[x] && dep[lca[nxt[x] / 2]] >= dep[u])
      nxt[x] = nxt[nxt[x]];  //删除lca低于u的路径
  } else
    head[u] = 0;
  int y = nxt[x];
  if (y) {
    ans++;
    mindep = std::max(dep[lca[x / 2]], dep[lca[y / 2]]);
    merge(x / 2, y / 2, !((x & 1) ^ (y & 1)));
  } else
    head[u] = x;
  return mindep;
}

inline int main() {
  int n, m, x, y;
  cin >> n >> m;
  for (int i = 1; i < n; ++i) cin >> x >> y, add(x, y);
  for (int i = 1; i <= m; ++i) fa[i] = i;
  dep[1] = 1, dfs1(1, 0);
  for (int i = 2; i <= cnt; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = 1; i < BIT; ++i) {
    for (int j = 1; j + (1 << i) - 1 <= cnt; ++j)
      f[i][j] = min(f[i - 1][j], f[i - 1][j + (1 << i - 1)]);
  }
  for (int i = 1; i <= m; ++i) {
    cin >> u[i] >> v[i];
    lca[i] = getLCA(u[i], v[i]);
    if (head[u[i]]) nxt[head[u[i]]] = i * 2;
    else
      begin[u[i]] = i * 2;
    head[u[i]] = i * 2;
    if (head[v[i]]) nxt[head[v[i]]] = i * 2 + 1;
    else
      begin[v[i]] = i * 2 + 1;
    head[v[i]] = i * 2 + 1;
  }
  dfs(1, 0);
  cout << ans << '\n';
  for (int i = 1; i <= m; ++i) {
    find(i);
    if (rev[i]) std::swap(u[i], v[i]);
    cout << u[i] << ' ' << v[i] << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("walk.in", "r", stdin);
  freopen("walk.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
